package cn.doctor.assistant.pad.ui.ziliao;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.doctor.assistant.pad.R;
import cn.doctor.assistant.pad.entity.Patient;

/**
 * Created by jiaolf on 2016/3/30.
 */
public class InfoAdapter extends BaseAdapter {

    private List<Patient> items;
    private int mLayoutResourceId;
    private Context context;

    public InfoAdapter(Context context,
                       int layoutResourceId,
                       List<Patient> data) {

        this.context = context;
        items = data;
        mLayoutResourceId = layoutResourceId;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        Patient patient = items.get(position);

        if (convertView == null) {
            convertView = LayoutInflater.from(context)
                    .inflate(mLayoutResourceId, parent, false);
            holder = new ViewHolder();

            holder.id = (TextView) convertView.findViewById(R.id.list_item_id);
            holder.name = (TextView) convertView.findViewById(R.id.list_item_name);
            holder.sex = (TextView) convertView.findViewById(R.id.list_item_sex);
            holder.phone = (TextView) convertView.findViewById(R.id.list_item_phone);
            holder.marriage = (TextView) convertView.findViewById(R.id.list_item_marriage);
            holder.address = (TextView) convertView.findViewById(R.id.list_item_address);
            holder.birthday = (TextView) convertView.findViewById(R.id.list_item_birthday);
            holder.note = (TextView) convertView.findViewById(R.id.list_item_note);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.id.setText(String.valueOf(position + 1));
        holder.name.setText(patient.getName());
        holder.sex.setText(patient.getSexString());
        holder.phone.setText(patient.getPhone());
        holder.birthday.setText(patient.getBirthday());
        holder.marriage.setText(patient.getMarriageString());
        holder.address.setText(patient.getAddress());
        holder.note.setText(patient.getNote());

        return convertView;
    }

    class ViewHolder {
        TextView id;
        TextView name;
        TextView sex;
        TextView phone;
        TextView birthday;
        TextView marriage;
        TextView address;
        TextView note;
    }
}
